package com.gouzheng.util;

import javax.servlet.http.HttpSession;

/**
 * Created by de'l'l on 2020/3/20.
 */
public class SessionCache {
    //线程绑定
    private ThreadLocal<HttpSession> threadLocal= new ThreadLocal<>();

    private static SessionCache sessionCache= new SessionCache();

    public SessionCache() {

    }

    public ThreadLocal<HttpSession> getThreadLocal() {
        return threadLocal;
    }

    public void setThreadLocal(ThreadLocal<HttpSession> threadLocal) {
        this.threadLocal = threadLocal;
    }

    public static SessionCache getSessionCache() {
        return sessionCache;
    }

    public static void setSessionCache(SessionCache sessionCache) {
        SessionCache.sessionCache = sessionCache;
    }

    //把session传入线程
    public void saveSession(HttpSession httpSession) {
        threadLocal.set(httpSession);
    }

    //取session
    public HttpSession getSession(){
        return threadLocal.get();
    }
}